<?php

namespace Frieza\Modules\User\Controllers;

use App\Http\Controllers\Controller;
use Doraemon\tools\Area;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Illuminate\Http\Request;


class IndexController extends Controller
{
    const PAGE_SIZE = 20;

    public function __construct()
    {
        parent::__construct();
        Admin::script('$(".pjax-container").attr("id","pjax-container");');
    }

    public function index(Request $request, Content $content)
    {
        $request = $request->all();

        return $content
            ->header('用户列表')
            ->description(' ')
            ->breadcrumb(
                ['text' => '用户列表']
            );
    }

    public function area(Request $request)
    {
        $pid = $request->input('q', 0);
        $areas = Area::getLocation($pid);
        $format = array_map(function($k, $v){
            return [
                'id' => $k,
                'text' => $v,
            ];
        }, array_keys($areas), $areas);
        return response()->json($format);
    }
}
